/**
 *
 */
package com.bsoft.gol.hcb.dao;

import ctd.persistence.annotation.DAOMethod;
import ctd.persistence.annotation.DAOParam;
import ctd.persistence.support.hibernate.template.HibernateSessionTemplate;
import org.atag.dao.action.QoHibernateStatelessResultAction;
import org.atag.dao.model.PageInfo;
import pcn.bean.sign.PcnHealthActivitiesQo;
import pcn.bean.sign.PcnHealthNewsQo;
import pcn.sign.PcnCmsAction;
import pcn.vo.sign.PcnHealthActivitiesAppVO;
import pcn.vo.sign.PcnHealthActivitiesVO;
import pcn.vo.sign.PcnHealthNewsAppVo;
import pcn.vo.sign.PcnHealthNewsVo;

import java.util.List;

/**
 * @since 2017-05-05 04:34:02
 */
public abstract class PcnCmsActionDAO extends ctd.persistence.support.hibernate.HibernateSupportDelegateDAO<PcnCmsAction> {

    public PcnCmsActionDAO() {
        this.setKeyField("id");
    }

    @DAOMethod(sql = "from PcnCmsAction where uid=:userId and action=:action and businessObjId=:businessObjId and businessType=:type")
    public abstract PcnCmsAction getPcnCmsActionByUserIdAndBusinessObjId(@DAOParam("userId") String userId, @DAOParam("businessObjId") String businessObjId, @DAOParam("action") String action, @DAOParam("type") String type);

    @DAOMethod(sql = "from PcnCmsAction where uid=:userId and businessObjId=:businessObjId and businessType=:type")
    public abstract List<PcnCmsAction> findListByUserIdAndBusinessObjId(@DAOParam("userId") String userId, @DAOParam("businessObjId") String businessObjId, @DAOParam("type") String type);


    public PcnHealthNewsVo getUserMarkInfo(PcnHealthNewsQo qo,final String type) {
        QoHibernateStatelessResultAction<PcnHealthNewsAppVo, PcnHealthNewsQo> action = new QoHibernateStatelessResultAction(true, qo, PcnHealthNewsAppVo.class);
        action.setSql("SELECT {{a.business_obj_id as id}} from  pcn_cms_action a where a.action='mark' and a.business_type=:businessType ");
        action.addCondition("  and a.uid=:uid ");
//        action.addCondition(" and b.category =:category");
        action.addSql(" ORDER BY a.created desc");
        action.addParamValue("uid", qo.getUid());
        action.addParamValue("businessType", type);
        HibernateSessionTemplate.instance().execute(action);
        PageInfo<PcnHealthNewsAppVo> pageInfo = action.getResultPage();
        PcnHealthNewsVo pcv = new PcnHealthNewsVo();
        pcv.setPageNo(pageInfo.getPageNum());
        pcv.setPageSize(pageInfo.getPageSize());
        pcv.setList(pageInfo.getList());
        pcv.setTotal(pageInfo.getTotal());
        return pcv;
    }

    public PcnHealthActivitiesAppVO getUserMarkInfoActivities(PcnHealthActivitiesQo qo, final String type) {
        QoHibernateStatelessResultAction<PcnHealthActivitiesVO, PcnHealthActivitiesQo> action = new QoHibernateStatelessResultAction(true, qo, PcnHealthActivitiesVO.class);
        action.setSql("SELECT {{a.business_obj_id as id}} from  pcn_cms_action a where a.action='mark' and a.business_type=:businessType ");
        action.addCondition("  and a.uid=:uid ");
//        action.addCondition(" and b.category =:category");
        action.addSql(" ORDER BY a.created desc");
        action.addParamValue("uid", qo.getUid());
        action.addParamValue("businessType", type);
        HibernateSessionTemplate.instance().execute(action);
        PageInfo<PcnHealthActivitiesVO> pageInfo = action.getResultPage();
        PcnHealthActivitiesAppVO pcv = new PcnHealthActivitiesAppVO();
        pcv.setPageNo(pageInfo.getPageNum());
        pcv.setPageSize(pageInfo.getPageSize());
        pcv.setList(pageInfo.getList());
        pcv.setTotal(pageInfo.getTotal());
        return pcv;
    }



}